﻿using System;
using Jayden.Dll.Core.Persistence.Queries.Enums;

namespace Jayden.Dll.Core.Persistence.Queries
{
	public class QueryFilterBinary : QueryFilter
	{
		private QueryFilterBinaryOperator m_Operator = QueryFilterBinaryOperator.Equals;
		private QueryFilterBinaryOperand m_Left;
		private QueryFilterBinaryOperand m_Right;

		public QueryFilterBinary(QueryFilterBinaryOperator o, QueryFilterBinaryOperand left, QueryFilterBinaryOperand right)
		{
			m_Operator = o;
			m_Left = left;
			m_Right = right;
		}

		public QueryFilterBinaryOperator Operator { get { return m_Operator; } set { m_Operator = value; } }
		public QueryFilterBinaryOperand Left { get { return m_Left; } set { m_Left = value; } }
		public QueryFilterBinaryOperand Right { get { return m_Right; } set { m_Right = value; } }

		public string OperatorString
		{
			get
			{
				switch (m_Operator)
				{
					case QueryFilterBinaryOperator.Equals:
						return "=";
					case QueryFilterBinaryOperator.NotEquals:
						return "<>";
					case QueryFilterBinaryOperator.Greater:
						return ">";
					case QueryFilterBinaryOperator.GreateOrEquals:
						return ">=";
					case QueryFilterBinaryOperator.Lower:
						return "<";
					case QueryFilterBinaryOperator.LowerOrEquals:
						return "<=";
					case QueryFilterBinaryOperator.Like:
						return "LIKE";
					default:
						throw new InvalidOperationException();
				}
			}
		}

		public override string ToString()
		{
			return string.Format("{0} {1} {2}", m_Left, OperatorString, m_Right);
		}
	}
}
